package com.lge.clock.alarmclock;
  
import com.lge.clock.util.CommonUtil;//[suhyun99.kim][1395] 2011.10.27
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;

/**
 *  when boot & timezone change, class run 
 * @author donggeun.kim
 *
 */
public class ALBootInit extends BroadcastReceiver {
	private static final String TAG = "ALBootInit";
	private boolean isBootCompleted;//[hyunjung78.park][1407] 2011.10.12 START
	
	/**
     * Sets alarm on ACTION_BOOT_COMPLETED.  Resets alarm on
     * TIME_SET, TIMEZONE_CHANGED
     * @param context Context
	 * @param intent Intent
	 */      
    @Override  
    public void onReceive(Context context, Intent intent) {
    	SharedPreferences mPrefs;//[hyunjung78.park][1407] 2011.10.12 START
        String action = intent.getAction();
      
       Log.d(TAG, "====action==>" + action );
        
        if (context.getContentResolver() == null) 
        {
            Log.d(TAG, "Alarm ALBootInit: FAILURE unable to get content resolver.  Alarms inactive.");
            return;
        }      
        //TD#17257 fixed by mo2sangbong.lee@lge.com 2011.07.23 the if statement move to here
		if (action.equalsIgnoreCase("android.intent.action.BOOT_COMPLETED")) {
			Log.d(TAG, "Alarm ALBootInit: BOOT_COMPLETED");
			Alarms.disableExpiredAlarms(context, true);
			Alarms.snoozeActivating(context);           
			Alarms.setNextAlert(context);
		 	
			Intent aa = new Intent();     
			aa.setAction( "alarm.current.nextAlarm" );
			context.sendBroadcast(aa); 
			
			/*[START] 2012.03.05 suein1209.kim VT Call State issue*/
			SharedPreferences mVtCallPrefs = context.getSharedPreferences("VT_CALL_IN_OR_OUT_STATE", 0);
			mVtCallPrefs.edit().putBoolean ("VTCALL_IN_STATE", false).commit();
			/*[END] 2012.03.05 suein1209.kim VT Call State issue*/
			
        	//SharedPreferences mPrefs;//[hyunjung78.park][1407] 2011.10.12 START
        	mPrefs = context.getSharedPreferences("VOICE_VIDEO_RECORD_PLAYING", 0);    
        	int play_state = mPrefs.getInt("PLAY_STATE", -1);
        	
    		Log.d("onResume", "===before===>  play_state===> " +  play_state);
    		mPrefs.edit().putInt("PLAY_STATE", 0).commit();
        	
        	mPrefs = context.getSharedPreferences("ALARM_BOOT_COMPLETED", 0);//[hyunjung78.park][1407] 2011.10.12 START
        	mPrefs.edit().putBoolean ("BOOT_COMPLETED", true).commit();//[hyunjung78.park][1407] 2011.10.12 START
        	/*[START] 2012.02.03 suein1209.kim*/
			//[suhyun99.kim][1395] 2011.10.27. START
//			int volumeID = android.os.FileUtils.getFatVolumeId(CommonUtil.getExternalStorageDirectory());
//	        mPrefs = context.getSharedPreferences("EXTERNAL_SDCARD_STATE", 0);
//	        mPrefs.edit().putInt("sdcardid", volumeID).commit();
//    		Log.d(TAG, "===sdcardid boot event===" +  volumeID);
			//[suhyun99.kim][1395] 2011.10.27. END
        	/*[END] 2012.02.03 suein1209.kim*/
    		return ;
        } ////////////////////////////////////////////////////////////////////////
	    

    	mPrefs = context.getSharedPreferences("ALARM_BOOT_COMPLETED", 0);//[hyunjung78.park][1407] 2011.10.12 START
    	isBootCompleted = mPrefs.getBoolean("BOOT_COMPLETED", false);//[hyunjung78.park][1407] 2011.10.12 START
		//[mo2sangbong.lee] 2011.08.16 TD#21572 Do not alert alarm when date change at settings app START
		
		//if (action.equalsIgnoreCase("android.intent.action.TIME_SET")) {
		if (isBootCompleted) { //[hyunjung78.park][1407] 2011.10.12  
			Log.d(TAG, "Alarm ALBootInit: TIME_SET");
			Alarms.setNextAlert(context);
		}
		//[mo2sangbong.lee] 2011.08.16 TD#21572 Do not alert alarm when date change at settings app END	    
    }  
}     

